package test;
import java.util.Scanner;
public class gj {
    static int max=0;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int x=scan.nextInt();
        int d=scan.nextInt();
        int[] a=new int[x];
        for(int i=0;i<x;i++){
            a[i]=scan.nextInt();
        }

        boolean[] flag=new boolean[1000];
        dfs(d,x,0,a,flag,0);
        System.out.println(max);

        scan.close();
    }
    public static void dfs(int d,int x,int j,int[] a,boolean[] flag,int sum){
        if(sum>max){
            max=sum;
        }
        for(int i=j;i<x;i++){
            if (!flag[i]){
                flag[a[i]+d]=true;
                dfs(d,x,i+1,a,flag,sum+1);
                flag[a[i]+d]=false;
            }

        }

    }
}
